
#include "StdDefs.h"
#include "LinkList.h"
#import <UIKit/UIKit.h>

@interface CLinkListNode : NSObject
{
	void * pData;
};
@property(readwrite,assign) void * pData;
@end

@implementation CLinkListNode
@synthesize pData;
@end

CLinkList::CLinkList()
{
	m_pList = [[NSMutableArray alloc] init];
}

CLinkList::~CLinkList()
{
	RemoveAll();
	[(NSMutableArray*)m_pList release];
}

int16 CLinkList::Count()
{
	return [(NSMutableArray*)m_pList count];
}

void CLinkList::AddData(void *data,int16 index)
{
	CLinkListNode *node =  [[CLinkListNode alloc] init];
	[node setPData:data];
	if(index >= 0 && index < Count())
		[(NSMutableArray*)m_pList insertObject:node atIndex:index];
	else
		[(NSMutableArray*)m_pList addObject:node];
}

void * CLinkList::GetData(int16 index)
{
	CLinkListNode *node = [(NSMutableArray*)m_pList objectAtIndex:index];
	return [node pData];
}

void CLinkList::Remove(int16 index)
{
	[[(NSMutableArray*)m_pList objectAtIndex:index] release];
	[(NSMutableArray*)m_pList removeObjectAtIndex:index];
}

void CLinkList::RemoveAll()
{
	int16 count = [(NSMutableArray*)m_pList count];
	for(int i=0;i<count;i++)
	{
		[[(NSMutableArray*)m_pList objectAtIndex:i] release];
	}
	[(NSMutableArray*)m_pList removeAllObjects];
}
